package com.xyhy.starter.mfx;

import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.core.FlexGlobalConfig;
import com.xyhy.starter.mfx.entity.IAuditable;
import com.xyhy.starter.mfx.listener.MfxObjectInsertListener;
import com.xyhy.starter.mfx.listener.MfxObjectUpdateListener;
import org.springframework.context.annotation.Configuration;
import jakarta.annotation.PostConstruct;


@Configuration
public class MfxConfig {

  @PostConstruct
  private void init() {
    FlexGlobalConfig config = FlexGlobalConfig.getDefaultConfig();

    config.registerInsertListener(new MfxObjectInsertListener(), IAuditable.class);
    config.registerUpdateListener(new MfxObjectUpdateListener(), IAuditable.class);

    FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
    keyConfig.setKeyType(KeyType.None);
    config.setKeyConfig(keyConfig);

    config.setLogicDeleteColumn("deleted");
  }

}
